/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.web.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Date: 2017/9/19
 * Time: 22:37
 *
 * @author bifrost
 * @version 1.0.0
 */
@RestController
@RequestMapping(value = "/test")
public class TestController {
    /*@Autowired
    DataSource dataSource;
    @RequestMapping(value = "/info")
    public Map getTestInfo() throws SQLException {
        ConnectionPool pool = dataSource.getPool();
        Connection conn=null;
        String table="PRODUCT_SKU";
        Map resultMap=new HashMap<String,String>();
        List<Map> columnList=new ArrayList<Map>();
        List<Map> primaryKeyList=new ArrayList<Map>();
        List<Map> foreignKeyList=new ArrayList<Map>();
        try{
            conn= pool.getConnection();
            if(conn!=null){
                DatabaseMetaData dbMetaData = conn.getMetaData();
                if(!dbMetaData.getDatabaseProductName().equalsIgnoreCase("MYSQL")){

                    resultMap.put("success","-1");
                    resultMap.put("message","不支持的数据库类型");
                }
                resultMap.put("primaryKey",primaryKeyList);
                //获取数据库名
                String catalog = conn.getCatalog(); //catalog 其实也就是数据库名
                //获取主键
                ResultSet primaryKeyResultSet = dbMetaData.getPrimaryKeys(catalog,null,table);
                while(primaryKeyResultSet.next()){
                    String primaryKeyColumnName = primaryKeyResultSet.getString("COLUMN_NAME");
                    Map m = new HashMap<String,String>();
                    m.put("primaryKey",primaryKeyColumnName);
                    primaryKeyList.add(m);
                }
                resultMap.put("foreignKey",foreignKeyList);
                //获取外键
                ResultSet foreignKeyResultSet = dbMetaData.getImportedKeys(catalog,null,table);
                while(foreignKeyResultSet.next()){
                    String fkColumnName = foreignKeyResultSet.getString("FKCOLUMN_NAME");
                    String pkTablenName = foreignKeyResultSet.getString("PKTABLE_NAME");
                    String pkColumnName = foreignKeyResultSet.getString("PKCOLUMN_NAME");
                    Map m = new HashMap<String,String>();
                    m.put("fkColumnName",fkColumnName);
                    m.put("pkTablenName",pkTablenName);
                    m.put("pkColumnName",pkColumnName);
                    foreignKeyList.add(m);
                }
                resultMap.put("column",columnList);
                ResultSet rs = dbMetaData.getColumns(catalog,null,table,null);
                while(rs.next()){
                    String columnName = rs.getString("COLUMN_NAME");
                    String columnType = rs.getString("TYPE_NAME");
                    int datasize = rs.getInt("COLUMN_SIZE");
                    int digits = rs.getInt("DECIMAL_DIGITS");
                    int nullable = rs.getInt("NULLABLE");
                    Map m = new HashMap<String,String>();
                    m.put("columnName",columnName);
                    m.put("columnType",columnType);
                    m.put("datasize",datasize);
                    m.put("digits",digits);
                    m.put("nullable",nullable);
                    columnList.add(m);
                }
            }
        }catch (exception e){
            throw new RuntimeException("获取数据库表信息失败，表名：" + table, e);
        }
        finally {
            if(conn!=null)conn.close();
        }
        return  resultMap;

    }*/
}
